package com.easy.service.impl;

import com.easy.bean.Quality_inspection;
import com.easy.mapper.QualityInspectionDao;
import com.easy.service.QualityInspectionService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QualityInspectionServiceImpl implements QualityInspectionService {

    @Autowired
    private QualityInspectionDao qualityInspectionDao;

    @Override
    public Quality_inspection add(Quality_inspection inspection) {
        // 如果is_deleted为空，则设置为默认值（未删除）
        if (inspection.getIs_deleted() == null) {
            inspection.setIs_deleted((byte)0); // 数据库中0表示未删除
        }
        qualityInspectionDao.add(inspection);
        // 确保能正确获取到插入后的记录
        if (inspection.getId() != null) {
            return qualityInspectionDao.one(inspection.getId());
        }
        // 如果无法通过ID获取，返回插入的对象
        return inspection;
    }

    @Override
    public int del(Integer id) {
        return qualityInspectionDao.del(id);
    }

    @Override
    public Quality_inspection edit(Quality_inspection inspection) {
        qualityInspectionDao.edit(inspection);
        return qualityInspectionDao.one(inspection.getId());
    }

    @Override
    public List<Quality_inspection> all(Integer productionOrderId, Integer purchaseOrderId, Integer inspectorId) {
        return qualityInspectionDao.all(productionOrderId, purchaseOrderId, inspectorId);
    }

    @Override
    public Quality_inspection one(Integer id) {
        return qualityInspectionDao.one(id);
    }

    @Override
    public void page(Page page, Quality_inspection inspection) {
        int count = qualityInspectionDao.pageCount(inspection);
        List<Quality_inspection> data = qualityInspectionDao.page(page, inspection);
        page.setCount(count);
        page.setData(data);
    }
}